package cn.sciento.farm.devicemanager.gateway.model.downlink;

import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

import static cn.sciento.farm.devicemanager.common.constant.MqttConstant.*;

/**
 * @author Walton
 * @since 2020/8/21 17:07
 */
@Data
public class InsectLampSwitchData extends AbstractBlockData {

    private Integer modbusAddr;

    private Long id;

    private String eui;

    private Integer upDoorSwitch;

    private Integer lowDoorSwitch;

    private Integer heatSwitch;

    private Integer lightSwitch;

    private Integer sweepSwitch;

    private Integer tileSwitch;

    private Integer phtotsSwitch;

    private Integer timeSwitch;

    private Integer lighthouseSwitch;

    private Integer statusRefresh;

    @Override
    public MqttContent generate() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", modbusAddr);
        map.put("upDoorSw", upDoorSwitch);
        map.put("lowDoorSw", lowDoorSwitch);
        map.put("heatSw", heatSwitch);
        map.put("lightSw", lightSwitch);
        map.put("sweepSw", sweepSwitch);
        map.put("tileSw", tileSwitch);
        map.put("phtotsSw", phtotsSwitch);
        map.put("timeSw", timeSwitch);
        map.put("lighthSw", lighthouseSwitch);
        map.put("statusRefresh", statusRefresh);
        String payload = JSON.toJSONString(map);
        String topic = String.format(ISM_CONTROL_TOPIC, eui);
        return new MqttContent(topic, payload);
    }

    @Override
    public String generateId() {
        return String.format(ISM_CONTROL_SWITCH_BLOCK_ID, eui);
    }

    @Override
    public String generateStatus() {
        return null;
    }
}
